package com.fenshi.presenter.imp;

import android.app.Activity;
import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.android.volley.VolleyError;
import com.fenshi.bean.OrderBean;
import com.fenshi.interactor.RentOrBackInteractor;
import com.fenshi.interactor.imp.RentOrBackInteractorImp;
import com.fenshi.manager.R;
import com.fenshi.presenter.RentOrBackPresenter;
import com.fenshi.presenter.listener.RequestListener;
import com.fenshi.until.CookicUntil;
import com.fenshi.view.RentOrBackView;

/**
 * Created by lilongfei on 15/10/11.
 */
public class RentOrBackPresenterImp implements RentOrBackPresenter, RequestListener<JSONObject> {

    Context c;
    RentOrBackView view;
    RentOrBackInteractor interactor;

    public RentOrBackPresenterImp(Context c) {
        this.c = c;
        view = (RentOrBackView) c;
        interactor = new RentOrBackInteractorImp(c, this);
    }


    @Override
    public void lockOrUnlockCar() {

    }

    @Override
    public void backOrder() {

    }

    @Override
    public void initViewAndEvent() {
        if (((Activity) c).getIntent().getExtras() != null) {
            OrderBean orderBean = (OrderBean) ((Activity) c).getIntent().getExtras().getSerializable(CookicUntil.ORDER);
            if (orderBean != null)
                view.initViewAndData(orderBean);
            else
                view.showError("订单传输错误");
        }
        view.showError("订单传输错误");
    }

    @Override
    public void Success(String tag, JSONObject result) {
        view.dimissLoad();

    }

    @Override
    public void Error(String tag, String error) {
        view.dimissLoad();
        view.showError(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.dimissLoad();
        view.showError(c.getString(R.string.system_error));
    }
}
